package com.study.zzedu.ui.schoolroll.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.study.zzedu.R;
import com.study.zzedu.adapter.CourseDetailAdapter;
import com.study.zzedu.entity.CourseDetailItem;
import com.study.zzedu.utils.LogUtil;
import com.study.zzedu.utils.Utils;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import static com.study.zzedu.ui.schoolroll.SchoolRollActivity.schoolRollInfo_personalInfo;

/**
 */

public class SchoolRollFragment extends Fragment {

    private List<CourseDetailItem> dataList = new ArrayList<CourseDetailItem>();
    CourseDetailAdapter courseDetailAdapter;
    RecyclerView mRecyclerView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_school_roll, container, false);
        initView(rootView);
        return rootView;
    }
    protected void initView(View view) {

        mRecyclerView = (RecyclerView) view.findViewById(R.id.rv_list_data);
        LinearLayoutManager lm = new LinearLayoutManager(getContext());
        mRecyclerView.setLayoutManager(lm);
        try {
            if(schoolRollInfo_personalInfo == null)
                return;
            JSONObject job = schoolRollInfo_personalInfo;
            dataList.add(new CourseDetailItem("教学点", Utils.getDefaultStringValue(job,"depart"),CourseDetailItem.TYPE_STRING ));
            dataList.add(new CourseDetailItem("学号",Utils.getDefaultStringValue(job,"userCode"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("专业",Utils.getDefaultStringValue(job,"major"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("培养层次",Utils.getDefaultStringValue(job,"level"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("学习形式",Utils.getDefaultStringValue(job,"learnType"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("学生类别",Utils.getDefaultStringValue(job,"studentType"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("班级",Utils.getDefaultStringValue(job,"className"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("年制",Utils.getDefaultStringValue(job,"learnLength"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("学籍状态",Utils.getDefaultStringValue(job,"curStatus"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("年级",Utils.getDefaultStringValue(job,"grade"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("专业类别",Utils.getDefaultStringValue(job,"majorType"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("在校状态",Utils.getDefaultStringValue(job,"schoolType"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("考生号",Utils.getDefaultStringValue(job,"num"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("报考专业类别",Utils.getDefaultStringValue(job,"subjects"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("入学日期",Utils.getDefaultStringValue(job,"enterDate"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("总分",Utils.getDefaultStringValue(job,"score"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("毕业照片",Utils.getDefaultStringValue(job,"graduationImg"),CourseDetailItem.TYPE_IMG));
            dataList.add(new CourseDetailItem("入学照片",Utils.getDefaultStringValue(job,"enterImg"),CourseDetailItem.TYPE_IMG));

            view.findViewById(R.id.rl_default_school_roll).setVisibility(View.GONE);

        }catch (Exception e){
            LogUtil.e("Exception",getActivity()+" "+e.toString());
            e.toString();
        }
        courseDetailAdapter = new CourseDetailAdapter(dataList);
        //mRecyclerView.addItemDecoration(new SpacesItemDecoration(30));
        mRecyclerView.setAdapter(courseDetailAdapter);
    }
}
